package com.example.libraryapp.network.base;

import android.util.Log;

import com.example.libraryapp.network.net.RetrofitException;

/**
 * @author 伍凯铭
 * @since 2020/2/28
 */
public abstract class BaseHttpHandler<T> implements IHttpListener<T> {

    private static final String TAG = "BaseHttpHandler";

    private IBaseView mView;

    protected BaseHttpHandler(IBaseView view) {
        this.mView = view;
    }

    @Override
    public void onComplete() {
        Log.e(TAG, "onComplete");
    }

    @Override
    public void onError(Throwable e) {
        RetrofitException.ResponseThrowable responseThrowable = RetrofitException.getResponseThrowable(e);
        Log.e(TAG, "e.code=" + responseThrowable.code + responseThrowable.message);

        if (mView != null) {
            if(responseThrowable.code == RetrofitException.NETWORD_ERROR) {
                mView.showNoNetwork(responseThrowable);
            }else {
                mView.showError(responseThrowable);
            }
        }
    }

}
